package zhoug.demo.zui.ui;

import android.os.Bundle;
import android.widget.Button;

import zhoug.logging.Logger;
import zhoug.zui.ZUICircleProgress;
import zhoug.demo.zui.R;

import androidx.appcompat.app.AppCompatActivity;

public class ZUICircleProgressActivity extends AppCompatActivity {
    private static final String TAG = ">>>ZUICircleProgressActiv";
    private static  boolean debug = false;

    private ZUICircleProgress mZUICircleProgress;
    private Button mBtnStart;
    private Button mBtnExchangeMode;

    private int progress = 0;
    private volatile boolean start = false;

    public static void setDebug(boolean debug) {
        ZUICircleProgressActivity.debug = debug;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zui_circle_progress);
        findViews();
        mBtnExchangeMode.setOnClickListener(v -> {
            if (mZUICircleProgress.getMode() == ZUICircleProgress.MODE_CENTER_TEXT) {
                mZUICircleProgress.setMode(ZUICircleProgress.MODE_CENTER_IMAGE);
            } else {
                mZUICircleProgress.setMode(ZUICircleProgress.MODE_CENTER_TEXT);
            }
        });
        mZUICircleProgress.setProgress(50);
        mZUICircleProgress.setOnProgressListener(new ZUICircleProgress.OnProgressListener() {
            @Override
            public void onProgress(int progress) {
                if (debug) {
                    Logger.d(TAG, "onProgress:progress=" + progress);
                }
            }
        });
        mBtnStart.setOnClickListener(v -> {
            if (start) {
                start = false;
            } else {
                start = true;
                progress = 0;
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        while (start && progress <= 100) {
                            mZUICircleProgress.setProgress(progress);
                            try {
                                Thread.sleep(100);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                            progress += 10;
                        }
                    }
                }).start();
            }


        });


    }


    private void findViews() {
        mZUICircleProgress = findViewById(R.id.ZUICircleProgress);
        mBtnStart = findViewById(R.id.btn_start);
        mBtnExchangeMode = findViewById(R.id.btn_exchangeMode);
    }
}